//
//  UIButton+Extension.swift
//  WeiBo
//
//  Created by chenguanglei on 16/11/25.
//  Copyright © 2016年 itheima. All rights reserved.
//

import UIKit

extension UIButton{

    // title
    // titlecoler
    // 字体大小
    // 背景图片
    // 圆角
    
    convenience init(titleNormal:String?,titleColor:UIColor?,size:CGFloat?,bgimageNormal:String?,imageNormal:String?,corner:CGFloat?) {
        
        self.init()
        
        self.setTitle(titleNormal, for: UIControlState.normal)
        
        self.setTitleColor(titleColor, for: UIControlState.normal)
        
        if let size = size {
            
            self.titleLabel?.font = UIFont.systemFont(ofSize: size)
        }
        
        if let imageName = imageNormal{
        
            self.setImage(UIImage(named: imageName), for: UIControlState.normal)
          
        }
        
        
        if let bgimageNormal = bgimageNormal{
        
            self.setBackgroundImage(UIImage(named:bgimageNormal), for: UIControlState.normal)
        
        }
        
        
        
        if let corner = corner {
            
            self.layer.cornerRadius = corner
            
        }
        
        
    }
    

    
    
    
    @IBInspectable var cornerRadius: CGFloat {
        get{
            return layer.cornerRadius
        }
        set{
            layer.cornerRadius = newValue
            layer.masksToBounds = cornerRadius > 0
        }
    }
    
    @IBInspectable var borderWidth: CGFloat {
        get{
            return layer.borderWidth
        }
        set{
            layer.borderWidth = newValue
        }
    }
    
    @IBInspectable var borderColor: UIColor? {
        get{
            guard let color = layer.borderColor else {
                return nil
            }
            return UIColor(cgColor: color)
        }
        set{
            layer.borderColor = newValue?.cgColor
        }
    }

    
    

}

